/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cageballcommon.messages;

import cageballcommon.*;
import cageballcommon.enummerations.TeamEnum;
import com.google.gson.Gson;

/**
 *
 * @author kanonas
 */
public class State {

    private long time;
    private Ball ball;
    private Team myTeam;
    private Team otherTeam;
    private Info info;

    public State(State state) {
        this.time = state.getTime();
        this.ball = new Ball(state.getBall());

        this.myTeam = new Team(state.getMyTeam());
        this.otherTeam = new Team(state.getOtherTeam());

        this.info = state.getInfo();
    }

    public State(String state) {
        Gson gson = new Gson();
        State newState = gson.fromJson(state, State.class);

        this.time = newState.getTime();
        this.ball = new Ball(newState.getBall());

        this.myTeam = new Team(newState.getMyTeam());
        this.otherTeam = new Team(newState.getOtherTeam());
        this.info = new Info(newState.getInfo());
    }

    public State(long time, Ball ball, Team myTeam, Team otherTeam) {
        this.time = time;
        this.ball = ball;
        this.myTeam = myTeam;
        this.otherTeam = otherTeam;
    }
    
    public State(long time, Ball ball, Team myTeam, Team otherTeam, Info info) {
        this(time, ball, myTeam, otherTeam);
        this.info = info;
    }

    public State() {
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public Ball getBall() {
        return ball;
    }

    public void setBall(Ball ball) {
        this.ball = ball;
    }

    public Team getMyTeam() {
        return myTeam;
    }

    public void setMyTeam(Team myTeam) {
        this.myTeam = myTeam;
    }

    public Team getOtherTeam() {
        return otherTeam;
    }

    public void setOtherTeam(Team otherTeam) {
        this.otherTeam = otherTeam;
    }

    public Info getInfo() {
        return info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    public boolean isGoal(){
        if(info != null){
            if(info.getGoal() != null){
                if(info.getGoal() != TeamEnum.none){
                    return true;
                }
            }
        }

        return false;
    }

    @Override
    public String toString() {
        return ball.toString();
    }
}
